package com.ruoyi.web.controller.shop.goods;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shop.goods.domain.ShopBrand;
import com.ruoyi.shop.goods.service.IShopBrandService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌信息controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */
@Controller
@RequestMapping("/shop/brand")
public class ShopBrandController extends BaseController
{
    private String prefix = "shop/goods/brand";

    @Autowired
    private IShopBrandService shopBrandService;

    @RequiresPermissions("shop:brand:view")
    @GetMapping()
    public String brand()
    {
        return prefix + "/brand";
    }

    /**
     * 查询brand列表
     */
    @RequiresPermissions("shop:brand:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopBrand brand)
    {
        startPage();
        List<ShopBrand> list = shopBrandService.selectBrandList(brand);
        return getDataTable(list);
    }

    /**
     * 导出brand列表
     */
    @RequiresPermissions("shop:brand:export")
    @Log(title = "brand", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopBrand brand)
    {
        List<ShopBrand> list = shopBrandService.selectBrandList(brand);
        ExcelUtil<ShopBrand> util = new ExcelUtil<ShopBrand>(ShopBrand.class);
        return util.exportExcel(list, "brand数据");
    }

    /**
     * 新增品牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存品牌
     */
    @RequiresPermissions("shop:brand:add")
    @Log(title = "brand", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopBrand brand)
    {
        return toAjax(shopBrandService.insertBrand(brand));
    }

    /**
     * 修改品牌
     */
    @RequiresPermissions("shop:brand:edit")
    @GetMapping("/edit/{brandId}")
    public String edit(@PathVariable("brandId") Long brandId, ModelMap mmap)
    {
        ShopBrand shopBrand = shopBrandService.selectBrandById(brandId);
        mmap.put("shopBrand", shopBrand);
        return prefix + "/edit";
    }

	/**
	 * 修改保存品牌
	 */
	@RequiresPermissions("shop:brand:edit")
	@Log(title = "brand", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ShopBrand brand) {
		return toAjax(shopBrandService.updateBrand(brand));
	}

	/**
	 * 删除品牌
	 */
	@RequiresPermissions("shop:brand:remove")
	@Log(title = "brand", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopBrandService.deleteBrandByIds(ids));
	}
}
